package com.hmall.item.web;

import com.hmall.common.dto.PageDTO;
import com.hmall.common.dto.SearchDTO;
import com.hmall.common.pojo.Item;
import com.hmall.common.pojo.ItemDoc;
import com.hmall.common.pojo.SearchVo;
import com.hmall.item.service.IItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("item")
public class ItemController {

    @Autowired
    private IItemService itemService;

    /**
     * 分页查询商品
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/list")
    public PageDTO<Item> getByPage(@RequestParam Integer page,@RequestParam Integer size){
        //log.info("分页查询商品,请求参数：{}",page,size);
        return itemService.getByPage(page,size);
    }
    @GetMapping("/{id}")
    public Item getById(@PathVariable("id") Long id){
        return itemService.getById(id);
    }

    @PostMapping()
    public void save(@RequestBody Item item){
      itemService.save(item);
    }

    @PutMapping()
    public void update(@RequestBody Item item){
        itemService.update1(item);
    }

    @PutMapping("/status/{id}/{status}")
    public void updateStatus(@PathVariable("id") Long id ,@PathVariable("status") Integer status){
        itemService.updateStatus(id,status);
    }
    @DeleteMapping("{id}")
    public void deleteByID(@PathVariable("id") Long id){
        itemService.removeById(id);
    }

    /**
     * 过滤项聚合功能
     * @return
     */
    @PostMapping("/filters")
    public SearchVo searchFilters(){
        return itemService.searchFilters();
    }

    /**
     * 基本搜索功能
     * @param dTO
     * @return
     */
    @PostMapping("/lists")
    public PageDTO<ItemDoc> searchList(@RequestBody SearchDTO dTO){
        return itemService.searchList(dTO);
    }

}
